package com.zch.date_;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 第三代日期类
 */
public class LocalDate_ {
    public static void main(String[] args) {
        LocalDateTime a = LocalDateTime.now();
        System.out.println(a);

        System.out.println(a.getYear());
        System.out.println(a.getMonth()); //November
        System.out.println(a.getMonthValue()); //11
        System.out.println(a.getDayOfMonth());
        System.out.println(a.getHour());
        System.out.println(a.getMinute());
        System.out.println(a.getSecond());

        LocalDateTime a1 = a.plusYears(25); //加上25年之后的时间
        System.out.println(a1);

        //利用DateTimeFormatter 注意是调用其方法ofPattern 而不是创建对象
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        //同样使用String类接收
        String s1 = dateTimeFormatter.format(a);
        System.out.println(s1);

        Instant instant= Instant.now();
        System.out.println(instant);
        Date date= Date.from(instant);
        Instant instant1=date.toInstant();
    }
}
